package euclidean

type tEuclideanCalculator struct {
}

func newEuclideanCalculator() IGCDCalculator {
	return &tEuclideanCalculator{}
}

func (me *tEuclideanCalculator) Calc(a, b int) int {
	if a <= 0 || b <= 0 {
		return 1
	}

	if a == b {
		return a
	}

	bigger := max(a, b)
	smaller := min(a, b)

	for smaller > 0 {
		remaining := bigger % smaller
		if remaining == 0 {
			return smaller
		} else {
			bigger ,smaller = smaller, remaining
		}
	}

	return 1
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

var EuclideanGCDCalculator = newEuclideanCalculator()